/*
 * To Do: Reinit form JQuery object.
 */
HCM.HitTemplateSelector = function(el) {
    var j_root_el = $(el);
    var hit_template_select;
    var template_container;

    this.onReady = function() {
        hit_template_select = j_root_el.find('#ddl_hit_template');
        template_container = j_root_el.find('#hit_properties');
        hit_template_select.change(function(){
            template_container.empty();
            getHitTemplate();
        });
    };

    var getHitTemplate = function() {
        $.get('/get/hpt',
        {
            hpid: hit_template_select.val(),
            rendererjson: 'True'
        }, getHitTemplateSuccess, 'html');
    };

    // data contains all the html code for template layout.
    var getHitTemplateSuccess = function(html) {
        template_container.append(html);
    };

};

$(function() {
    $('#hitForm').each(function () {
        new HCM.HitTemplateSelector(this).onReady();
    });
});

